home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1417_using_the_pasteFont_method.rtf < prev    next >
Text File  |  1993-11-08  |  2KB  |  52 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fmodern Ohlfs;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red84\green84\blue84;\red83\green83\blue83;\red82\green82\blue82;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I'm trying to use the 
  8. \f1\fs24\fc1\cf1 pasteFont:
  9. \f0\fs28\fc0\cf0  method of the Text object to extract font information from the Font Pasteboard.  The trouble is, when I try to do this, I always get the default font information—Helvetica 12pt.  What am I doing wrong?\
  10.  
  11. \i     \
  12.  
  13. \i0 A:  The solution is easy but perhaps not obvious.  In order for the paste operation to have any effect, the Text object must contain a selection.  It is not even strictly necessary that it contain any text.  The following code illustrates the “low-pain” method of extracting font values from the Pasteboard.  (The alternative “high-pain” method would involve parsing the rich text format from the Pasteboard):\
  14. \
  15. \
  16.  
  17. \f1\fs24\fc1\cf1     #import <appkit/Text.h>\
  18.     #import <appkit/Font.h>\
  19. \
  20.     \
  21.         id    font, myText;\
  22.     \
  23.         /* Allocate a temporary Text object */\
  24.         myText = [[Text alloc] init];\
  25.     \
  26.         /* It must allow multiple fonts -- i.e. rich text */\
  27.         [myText setMonoFont: NO];\
  28.     \
  29.         /* Stick in some text -- optional */\
  30.         [myText setText:"hello"];\
  31.     \
  32.         /* And select it -- any selection will do so long */\
  33.         /* as something is selected */\
  34.         [myText setSel:0  :1];\
  35.         \
  36.         /* pasteFont: will copy the font info from the Pasteboard\
  37.         /* to the font in the Text object */\
  38.         [myText pasteFont:sender];\
  39.     \
  40.         /* Do what you need to with the font */\
  41.         font = [myText font];\
  42.     \
  43.         /* Then free up the Text object */\
  44.         [myText free];\
  45.  
  46. \f0\fs28\fc0\cf0 \
  47. QA677\
  48. \
  49. Valid for 2.0, 3.0\
  50. \
  51.  
  52.